package com.example.wxback.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wxback.dao.IWxUserDao;
import com.example.wxback.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WxUserService extends ServiceImpl<IWxUserDao, UserInfo> {

    @Autowired
    private IWxUserDao wxUserDao;

    public int countUser() {
        return wxUserDao.countUser();
    }

    public List<UserInfo> getUserList(int page, int pageSize) {
        return wxUserDao.getUserList(page * pageSize, pageSize);
    }

    public UserInfo getUser(int id) {
        return wxUserDao.getUser(id);
    }

    public UserInfo getUserByPhone(String phone) {
        return wxUserDao.getUserByPhone(phone);
    }

    public boolean insertUser(UserInfo userInfo) {
        return wxUserDao.insertUser(userInfo) > 0;
    }

    public boolean updateUser(UserInfo userInfo) {
        return wxUserDao.updateUser(userInfo) > 0;
    }

    public boolean enableUser(UserInfo userInfo) {
        return wxUserDao.enableUser(userInfo) > 0;
    }

    public boolean deleteUser(Integer id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id", id);
        return baseMapper.delete(queryWrapper) > 0;
    }
}
